
import React from 'react';

import styles from './GoodsList.css';
import {Table, Divider, Tag, message} from 'antd';
import GiftGoodsService from "../../business/gift/GiftGoodsService";


const columns = [{
  title: '礼品名称',
  dataIndex: 'goodsName',
  key: 'goodsName',
  render: text => <a href="javascript:;">{text}</a>,
}, {
  title: '礼品编号',
  dataIndex: 'goodsSn',
  key: 'goodsSn',
  width:'20%',
}, {
  title: '积分',
  dataIndex: 'goodsPoints',
  key: 'goodsPoints',
}, {
  title: '库存',
  dataIndex: 'goodsQuantity',
  key: 'goodsQuantity',
}, {
  title: '浏览',
  dataIndex: 'clickCount',
  key: 'clickCount',
}, {
  title: '兑出',
  dataIndex: 'exchangeCount',
  key: 'exchangeCount',
}, {
  title: '操作',
  key: 'action',
  render: (text, record) => (
    <span>
      <a href="javascript:;">修改</a>
      <Divider type="vertical" />
    </span>
  ),
}];

const rowSelection = {
  onChange: (selectedRowKeys, selectedRows) => {
  },
  getCheckboxProps: record => ({
    disabled: record.name === 'Disabled User', // Column configuration not to be checked
    name: record.name,
  }),
};

class GoodsList extends React.Component{

  constructor(props) {
    super(props);
    this.state ={
      giftData:[]
    }
    this.giftGoodsService =new GiftGoodsService();
    this.callBackQueryList = this.callBackQueryList.bind(this);

  }
  giftGoodsService:GiftGoodsService;
  state ={
    giftData:[]
  }
  callBackQueryList(giftList,isSuccess){
    if(!isSuccess || giftList.code !="000000"){
      message.info(giftList.message);
    }else{
      this.setState({giftData: giftList.data.dataList});
    }
  }

  componentDidMount(){
    console.info("giftPage htpp start");
    let data ={
      username:sessionStorage.getItem('username')
    };
    this.giftGoodsService.queryList(this.callBackQueryList);
  }

  show(giftData:any[]){
    if(giftData.length !=0){
     return (<Table rowSelection={rowSelection} columns={columns} dataSource={giftData} rowKey={record=>record.goodsSn} />);
    }else{
      return "";
    }
  }




  render() {
    const {giftData} = this.state;
    return (
      <div className={styles.normal}>
        {this.show(giftData)}
      </div>
    );
  }
}

export default GoodsList;
